#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int maxSubarraySumCircular(vector<int>& nums)
    {
        int size = nums.size();
        int res = nums[0];
        vector<int> dp1(size + 1, 0);
        vector<int> dp2(size + 1, 0);
        int tmp = nums[0];
        int sum = 0;
        for (auto e : nums)
        {
            sum += e;
        }

        for (int i = 1; i < size + 1; i++)
        {
            dp1[i] = max(dp1[i - 1] + nums[i - 1], nums[i - 1]);
            dp2[i] = min(dp2[i - 1] + nums[i - 1], nums[i - 1]);
            res = max(res, dp1[i]);
            tmp = min(tmp, dp2[i]);
        }

        if (sum == tmp) return res;
        res = max(res, (sum - tmp));
        return res;

    }
};